<template>
  <div>
    <!-- # fields 预设的 可以在设计时选择的字段
    # formdata 设计好的表单json数据 (用于接着以前未设计完成的时表单接着设计)
    # save方法为触发保存的回调 返回的是设计好的表单的json 数据 -->
    <el-button style="margin:10px " type="primary" @click="GoFun" size="mini">返回</el-button>
    <formdesign :formdata="formdata"
                @save='saveform' />

  </div>
</template>

<script>
export default {
  data () {
    return {
      formdata: ''
    }
  },
  created () {
    // this.http.get("api/form/GetModelData?id=" + '1')
    //   .then(result => {
    //     console.log(result.table_configuration)
    //     this.formdata = JSON.parse(result.table_configuration)
    //   })
    console.log(this.$route.params.table_configuration)
    this.formdata = JSON.parse(this.$route.params.table_configuration)
    console.log(this.$route.params.id)
    console.log("创建页面")
  },
  methods: {

    saveform (data) {
      console.log(data)
      sessionStorage.setItem('ffdata', JSON.stringify(data))
      let keys = {
        "mainData": {
          "id": this.$route.params.id,
          "form_configuration": JSON.stringify(data.forms),
          "designer_configuration": JSON.stringify(data.formsetting),
          "table_configuration": JSON.stringify(data)
        },
        "detailData": null,
        "delKeys": null
      }
      this.http.post("/api/Form/Update", keys).then(() => {
        this.$message({
          showClose: true,
          message: '已保存',
          type: 'success'
        });
      });
    },
    GoFun () {
      this.$router.go(-1)
    },
  }
};
</script>